package cn.edu.ctbu.thymeleafwork.aspect;

import cn.edu.ctbu.thymeleafwork.exception.RException;
import cn.edu.ctbu.thymeleafwork.utils.RUtils;
import cn.edu.ctbu.thymeleafwork.vo.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(value = Exception.class)
    public R handle(Exception e){
        if (e instanceof RException) {
            RException rException=(RException) e;
            return RUtils.error(rException.getCode(),rException.getMessage());

        }
        return RUtils.error(-999, e.getMessage());
    }
}
